package com.ailiwu.www.ailiwu.base;

import android.app.Application;
import android.content.Context;
import android.util.DisplayMetrics;

import com.ailiwu.www.ailiwu.db.SQLHelper;
import com.ailiwu.www.ailiwu.utils.Logger;


/**
 * Author:    XiYoung
 * Version    V1.0
 * Date:      ${data}  ${time}
 * Description:用于初始化全局变量
 * Modification  History:
 * Date         	Author        		Version        	Description
 * -----------------------------------------------------------------------------------
 * 2015/11/31       author              1.0                   1.0
 * Why & What is modified:
 */
public class MyApplication extends Application {
    /**
     * 日志的开关，false:不打印log; true:打印log;
     */
    public static final boolean isDebug = true;
    /**
     * 全局上下文
     */
    public static Context mContext;
    /**
     * 屏幕的宽度
     */
    public static int mDisplayWitdh;

    /**
     * 屏幕的高度
     */
    public static int mDisplayHeight;
    private SQLHelper sqlHelper;
    private static MyApplication mApplication;



    @Override
    public void onCreate() {
        super.onCreate();
        mContext = getApplicationContext();
        initDisplay();
        mApplication = this;
    }

    /**
     * 初始化屏幕的宽高信息
     */
    private void initDisplay() {
        //初始化DisplayMetrics对象
        DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
        mDisplayHeight = displayMetrics.heightPixels;
        mDisplayWitdh = displayMetrics.widthPixels;
        Logger.d("height:" + mDisplayWitdh);
        System.out.println("进程id:" + android.os.Process.myPid());
    }


    /** 获取Application */
    public static MyApplication getApp() {
        return mApplication;
    }

    /** 获取数据库Helper */
    public SQLHelper getSQLHelper() {
        if (sqlHelper == null)
            sqlHelper = new SQLHelper(mContext);
        return sqlHelper;
    }

}
